<!-- 同行费用即将结算 -->
<template>
  <a-modal
    :visible="visible"
    @cancel="onClose"
    :title="pageTlt"
    :mask-closable="false"
    :align-center="false"
    class="modal-dialog-wrapper"
    destroyOnClose
    top="30px"
    width="85vw"
    okText="确认"
  >
    <div style="max-height: 85vh">
      <list-searcher :searchList="searchList" v-model:searchForm="queryParam" @loadData="loadData" />
      <table-index :table="table" :rowKey="`id`" @loadData="loadData">
        <template #contactName="{ record }">
          <div class="car-msg">
            <div class="car-msg-left">
              <div class="col-text">{{ record.contactName || '-' }} </div>
              <div class="col-text"> {{ record.contactPhone || '-' }} </div>
            </div>
          </div>
        </template>
        <template #operate="{ record }">
          <!-- 对账管理-借调对账 -->
          <view v-if="usePermission('svms:finance:reconciliation:transferReconciliation')">
            <a
              v-permission="'svms:finance:reconciliation:transferReconciliation'"
              class="operate-button"
              type="text"
              size="small"
              @click="onhandle(1, record)"
            >
              前往处理
            </a>
          </view>
          <!-- 资产-运维-车辆借调 -->
          <view v-else-if="usePermission('svms:asstes:operation:car-transfer')">
            <a
              v-permission="'svms:asstes:operation:car-transfer'"
              class="operate-button"
              type="text"
              size="small"
              @click="onhandle(2, record)"
            >
              前往处理
            </a>
          </view>
        </template>
      </table-index>
    </div>
    <template #footer>
      <a-button @click="onClose">关闭</a-button>
    </template>
  </a-modal>
</template>

<script setup name="txfytips">
  import { ref, reactive, computed } from 'vue'
  import { getIndustryBillList } from '@/api/workplace.js'
  import { useTable, useFetchTableDataApi } from '@/hooks/table'
  import { usePermission } from '@/hooks/usePermission'
  import useNavigate from '@/hooks/useNavigate'
  const { navigateTo } = useNavigate()

  //查询条件
  let queryParam = reactive({})
  const searchList = computed(() => {
    return [
      {
        label: '同行',
        prop: 'supplierId',
        type: 'remote-select',
        attrs: {
          type: 'sameIndustry_list',
          popupContainer: '.modal-dialog-wrapper .remote-select-wrapper',
        },
      },
      { label: '业务单信息', prop: 'refCode', type: 'a-input' },
    ]
  })
  // 待处理 - table 配置
  const table = useTable({
    tableHeight: 'calc(100vh - 350px)',
    columns: [
      { title: '业务单信息', dataIndex: 'refCode', width: 240 },
      { title: '待结金额', dataIndex: 'amount', unit: '元', width: 100 },
      { title: '应结日期', dataIndex: 'settlementDate', width: 170 },
      { title: '同行', dataIndex: 'industryName', width: 100 },
      { title: '同行联系人', dataIndex: 'contactName', slotName: 'contactName', width: 100 },
      { title: '提醒时间', dataIndex: 'warningTime', width: 170 },
      { title: '操作', dataIndex: 'operate', slotName: 'operate', width: 100 },
    ],
  })
  const onhandle = (status, record) => {
    if (status === 1) {
      navigateTo(`/finance/reconciliation/transferReconciliation?code=${record.refCode}`)
    } else if (status === 2) {
      navigateTo(`/assets/operation/car-transfer?code=${record.refCode}`)
    }
  }
  // 列表接口调用
  const loadData = useFetchTableDataApi(table, queryParam, getIndustryBillList)
  // modal展示
  const visible = ref(false)
  let pageTlt = ref('')
  const open = (label) => {
    pageTlt = label
    visible.value = true
    loadData(1)
  }
  const onClose = () => {
    visible.value = false
    queryParam.supplierId = ''
    queryParam.refCode = ''
  }
  defineExpose({
    open,
  })
</script>

<style lang="less" scoped>
  .car-msg {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .car-msg-left {
    margin-right: 10px;
  }
  .col-lic {
    color: #1d2129;
    font-size: 14px;
    font-weight: 600;
    margin-right: 16px;
  }
  .operate-button {
    width: 56px;
    display: inline-flex;
    align-items: center;
    line-height: 1.5715;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.1s cubic-bezier(0, 0, 1, 1);
    user-select: none;
    height: 32px;
    font-size: 14px;
    border-radius: var(--border-radius-small);
    color: rgb(var(--primary-6));
  }
</style>
